package mop.model.task.filter;

import java.util.LinkedList;
import java.util.List;

import mop.model.task.TaskInterface;
import mop.util.filter.Filter;

/**
 * Filer tasks based on status
 * @author MOP Team 7
 * 
 * @invar status != null
 *
 */
public class StateFilter implements Filter<TaskInterface>{

	/**
	 * Constructor
	 * @param status	Status we want to filter
	 * @effect Status is set
	 * 	|setStatus(status)
	 */
	public StateFilter(String status){
		setStatus(status);
	}
	
	/**
	 * The status we want to filter 
	 */
	private String status;
	
	/**
	 * Set status value we want to filter
	 * @param status
	 * @post Status is set to given value
	 * 	|getStatus() == status
	 */
	public void setStatus(String status){
		if(status == null)
			throw new IllegalArgumentException("Status is not set in status filter");
		
		this.status = status;
	}
	
	/**
	 * Return status filter value
	 * @return this.status
	 */
	public String getStatus(){
		return this.status;
	}
	
	/**
	 * @see Filter#filter(List)
	 */
	@Override
	public List<TaskInterface> filter(List<TaskInterface> list) {

		List<TaskInterface> copy = new LinkedList<TaskInterface>();
		
		for(TaskInterface t : list)
		{
			if(t.getStatus().toString().equals(getStatus()) || (getStatus().equals("Unfinished") && (t.getStatus().toString().equals("Available") || t.getStatus().toString().equals("Unavailable")))) 
				copy.add(t);
		}
			
		return copy;
	}

}
